//
//  ToolsTableViewCell.m
//  NBTripe
//
//  Created by 陈曦 on 16/1/11.
//  Copyright © 2016年 Vicki. All rights reserved.
//

#import "ToolsTableViewCell.h"

@interface ToolsTableViewCell ()
@property (nonatomic,strong) UIButton *button1;
@property (nonatomic,strong) UIButton *button2;
@property (nonatomic,strong) UIButton *button3;
@property (nonatomic,strong) UIButton *button4;
@property (nonatomic,strong) UIButton *button5;
@property (nonatomic,strong) UILabel *la1;
@property (nonatomic,strong) UILabel *la2;
@property (nonatomic,strong) UILabel *la3;
@property (nonatomic,strong) UILabel *la4;
@property (nonatomic,strong) UILabel *la5;
@property (nonatomic,copy) NSString *str1;




@end

@implementation ToolsTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        self.button1 = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.button1 addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        self.button1.tag = 101;
        [self.button1 setBackgroundImage:[UIImage imageNamed:@"Tool1"] forState:UIControlStateNormal];
        [self addSubview:self.button1];
        self.la1 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.la1.text = @"不可错过";
        self.la1.font = [UIFont systemFontOfSize:13];
        self.la1.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.la1];
        
        self.button2 = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.button2 addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        self.button2.tag = 102;
        [self.button2 setBackgroundImage:[UIImage imageNamed:@"Tool2"] forState:UIControlStateNormal];
        [self addSubview:self.button2];
        self.la2 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.la2.text = @"旅行地点";
        self.la2.font = [UIFont systemFontOfSize:13];
        self.la2.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.la2];
        
        self.button3 = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.button3 addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        self.button3.tag = 103;
        
        [self.button3 setBackgroundImage:[UIImage imageNamed:@"Tool3"] forState:UIControlStateNormal];
        [self addSubview:self.button3];
    
        self.la3 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.la3.text = @"主题榜单";
        self.la3.font = [UIFont systemFontOfSize:13];
        self.la3.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.la3];
        
        self.button4 = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.button4 addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        self.button4.tag = 104;
        [self.button4 setBackgroundImage:[UIImage imageNamed:@"Tool4"] forState:UIControlStateNormal];
        [self addSubview:self.button4];
        self.la4 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.la4.text = @"精品游记";
        self.la4.font = [UIFont systemFontOfSize:13];
        self.la4.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.la4];
        
        self.button5 = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.button5 addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        self.button5.tag = 105;
        [self.button5 setBackgroundImage:[UIImage imageNamed:@"Tool5"] forState:UIControlStateNormal];
        [self addSubview:self.button5];
        self.la5 = [[UILabel alloc] initWithFrame:CGRectZero];
        self.la5.text = @"实用须知";
        self.la5.font = [UIFont systemFontOfSize:13];
        self.la5.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.la5];
    }
    return self;
}

-(void)setDetaiedModel:(DetailedFirstModel *)detaiedModel {
    if (_detaiedModel != detaiedModel) {
        _detaiedModel = detaiedModel;
    }
    
    ToolsModel *tool =self.detaiedModel.toolsArray[0];
    self.str1 = tool.url;
    
    
    
  
}


- (void)buttonDidPress:(UIButton *)sender {
    switch (sender.tag) {
        case 101:
        
            self.toolsTiao(self.str1);
            
        
            break;
        case 102:
        {
            
            self.toolsDiDian(self.detaiedModel);
        }
            break;
        case 103:
        {
            ToolsModel *tool =self.detaiedModel.toolsArray[2];
            NSString *urls = tool.url;
            self.toolsTiao(urls);
            
        }
            break;
        case 104:
        {
            NSString *url = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%ld/%@/trips/", (long)self.detaiedModel.type, self.detaiedModel.nId];
            self.toolsJP(url);
            
        }
            break;
        case 105:
        {
            ToolsModel *tool =self.detaiedModel.toolsArray[5];
            NSString *urls = tool.url;
            self.toolsTiao(urls);
            
        }
            break;
    }
    
}

-(void)layoutSubviews {
    [super layoutSubviews];
    self.button1.frame = CGRectMake(self.width / 20, 0, self.width / 10, self.width / 10);
    
    self.button2.frame = CGRectMake(self.button1.right + self.width / 10, 0, self.button1.width, self.button1.height);
    self.button3.frame = CGRectMake(self.button2.right+ self.width / 10, 0, self.button1.width, self.button1.height);
    self.button4.frame = CGRectMake(self.button3.right+ self.width / 10, 0, self.button1.width, self.button1.height);
    self.button5.frame = CGRectMake(self.button4.right+ self.width / 10, 0, self.button1.width, self.button1.height);
    self.la1.frame = CGRectMake(0, self.button1.bottom + 5 * XHIGHT, self.width / 5, 40 * XHIGHT);
    self.la2.frame = CGRectMake(self.la1.right, self.button1.bottom + 5 * XHIGHT, self.width / 5, 40 * XHIGHT);
    self.la3.frame = CGRectMake(self.la2.right, self.button1.bottom + 5 * XHIGHT, self.width / 5, 40 * XHIGHT);
    self.la4.frame = CGRectMake(self.la3.right, self.button1.bottom + 5 * XHIGHT, self.width / 5, 40 * XHIGHT);
    self.la5.frame = CGRectMake(self.la4.right, self.button1.bottom + 5 * XHIGHT, self.width / 5, 40 * XHIGHT);
    
}


    
    

    
    


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
